package com.laviedesfons.jhmtasc.logging;

import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;

/**
 *
 * @author Romano
 */
public class CustomFormatter extends SimpleFormatter {

    @Override
    public String format(LogRecord r) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        if(!r.getLoggerName().isEmpty()){
            sb.append(r.getLoggerName()).append("-");
        }
        sb.append(r.getLevel().getName()).append("]..");
        if(!r.getSourceMethodName().isEmpty()){
            sb.append(r.getSourceMethodName()).append("()");
        }
        sb.append("......");
        if (r.getParameters() != null) {
            String msg = r.getMessage();
            for (int i = 0; i < r.getParameters().length; i++) {
                msg = msg.replace("{" + i + "}", r.getParameters()[i].toString());
            }
            sb.append(msg);
        } else {
            sb.append(r.getMessage());
        }
        sb.append("\r");
        return sb.toString();
    }
}
